//
// Created by Win10 on 2022/10/31.
//

#include "de_queue.h"

void InitQueue(DeQue &Q) {
    Q.front = Q.rear = Q.size = 0;
}

bool QueueEmpty(DeQue Q) {
    if (Q.size == 0) return true;
    return false;
}

bool QueueFull(DeQue Q) {
    if (Q.size == MaxSize) return true;
    return false;
}

bool EnQueue_Head(DeQue &Q, ElemType x) {
    if (QueueFull(Q)) return false;
    Q.front = (Q.front - 1 + MaxSize) % MaxSize;
    Q.data[Q.front] = x;
    Q.size++;
    return true;
}

bool EnQueue_Rear(DeQue &Q, ElemType x) {
    if (QueueFull(Q)) return false;
    Q.data[Q.rear] = x;
    Q.rear = (Q.rear + 1) % MaxSize;
    Q.size++;
    return true;
}

bool DeQueue_Head(DeQue &Q, ElemType &x) {
    if (QueueEmpty(Q)) return false;
    x = Q.data[Q.front];
    Q.front = (Q.front + 1) % MaxSize;
    Q.size--;
    return true;
}

bool DeQueue_Rear(DeQue &Q, ElemType &x) {
    if (QueueEmpty(Q)) return false;
    Q.rear = (Q.rear - 1 + MaxSize) % MaxSize;
    x = Q.data[Q.rear];
    Q.size--;
    return true;
}

bool GetHead(DeQue Q, ElemType &x) {
    if (QueueEmpty(Q)) {
        return false;
    }
    x = Q.data[Q.front];
    return true;
}

int GetSize(DeQue Q) {
    return Q.size;
}